<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>upload</title>
</head>

<body>
    <div><input type="file" name="file" onchange="uploadFile(this);" /> </div>
    <div>
        <pre id="ret-content"></pre>
    </div>
</body>
<script>
    function uploadFile(t) {
        if (t.files.length <= 0) {
            return;
        } else {
            let fm = new FormData();
            fm.append('image', t.files[0]); //append(key值（即name值），文件)，可以一直调用不断添加
            fetch('/upload', {
                method: 'POST',
                body: fm
            }).then(res => {
                return res.text();
            }).then(text => {
                let d = document.getElementById('ret-content');
                d.innerHTML = `<img src="/image/${text}" ` + ` style="width:80%;height:auto;"/>`;
            })
        }
    }
</script>

</html>